// JavaScript Document
function Checker()
{
	

	if($("#phone").val() == '' || $("#username").val() == '')
	{
		alert("Hãy nhập đầy đủ thông tin!");
		return false;
	}

	if(isNaN($("#phone").val()))
	{
		alert("Số điện thoại không hợp lệ!");
		$("#phone").focus();
		return false;
	}

	if($("#phone").val().toString().length<10)
	{
		alert("Số điện thoại không hợp lệ!");
		$("#phone").focus();
		return false;
	}
	
}
function requestGame(txtlink){
	showLoadingPage();
	url = "process/processRequest.php?link="+txtlink;
	http.open("get",url,true);
	http.onreadystatechange= function()
	{
		if(http.readyState == 4 && http.status == 200)
		{
		$("#ketqua").html(http.responseText);
		$("#loadingpage").fadeOut(1000);
	}}
	http.send(null);
}

function showSearchItune(){
	showLoadingPage();
	url = "process/processSearchItune.php";
	http.open("get",url,true);
	http.onreadystatechange= function()
	{
		if(http.readyState == 4 && http.status == 200)
		{
		$("#ketqua").html(http.responseText);
		$("#loadingpage").fadeOut(1000);
	}}
	http.send(null);
}
function searchGame(text,type,dev,page){
	showLoadingPage();
	url = "process/processSearch.php?text="+text+"&type="+type+"&page="+page+"&dev="+dev;
	http.open("get",url,true);
	http.onreadystatechange= function()
	{
		if(http.readyState == 4 && http.status == 200)
		{
		$("#ketqua").html(http.responseText);
		$("#loadingpage").fadeOut(1000);
	}}
	http.send(null);
}

function loadGameByGroup(id,p,type){

	url = "process/processGroupCopy.php?typeID="+id+"&page="+p+"&flag="+type;
	http.open("get",url,true);
	http.onreadystatechange= function()
	{
		if(http.readyState == 4 && http.status == 200){
		$("#groupGame"+type).html(http.responseText);	
	}}
	http.send(null);
}
function loadGameByAllGroup(id,p){

	url = "process/processGroupCopy.php?typeID="+id+"&page="+p;
	http.open("get",url,true);
	http.onreadystatechange=processByCate;
	http.send(null);
}

function processByCate(){
	if(http.readyState == 4 && http.status == 200){
		$('#ketqua').html(http.responseText);	
	}
}
function loadGameByCate(id,p){

	url = "process/processGroupCopy.php?cateID="+id+"&page="+p;
	http.open("get",url,true);
	http.onreadystatechange=processByCate;
	http.send(null);
}

function processByCate(){
	if(http.readyState == 4 && http.status == 200){
		$('#ketqua').html(http.responseText);	
	}
}
function checkout()
{
	if($("#countGame1").html() != "0")
	{
	$("#login-box").fadeIn(1000);
	
	$('body').append('<div id="mask1" onclick="javascript:exit();"></div>');
	$('#mask1').fadeIn(300);
	var popMargTop = ($("#login-box").height() + 24) / 2; 
	var popMargLeft = ($("#login-box").width() + 24) / 2; 
	
	$("#login-box").css({ 
		'margin-top' : -popMargTop,
		'margin-left' : -popMargLeft
	});
	}
	
}
function exit()
{
	$('#mask1 , .login-popup').fadeOut(300) ; 
	removeMask();
}
function removeMask(){$('#mask1').remove(); 
} 
	
function selecte(id)
{	
	for(i=1;i<6;i++)
	{
		var namee = "img"+i+"_"+id.toString();
		var obj=document.getElementById(namee);
		if(obj != null)
		{
			var class1 = obj.getAttribute('class');
				
			if(class1=='unSelect')
				{
					$("#img"+i+"_"+id).attr("src","img/mask175_check.png");
					obj.setAttribute('class','Selected');
				}
			else
				{
					$("#img"+i+"_"+id).attr("src","img/mask175_2.png");
					obj.setAttribute('class','unSelect');
				}
		}
	}

}
function mouseover(obj)
{	
	if(obj.getAttribute("class")=='unSelect')
		obj.src="img/mask175_Add.png";
	else
		obj.src="img/mask175_uncheck.png";

}
function mouseout(obj)
{	
	if(obj.getAttribute("class")=='unSelect')
		obj.src="img/mask175_2.png";
	else
		obj.src="img/mask175_check.png";
}

function createObject() 
{
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
	request_type = new XMLHttpRequest();
	}
	return request_type;
}

var http = createObject();

var nocache = 0;

function insert() 
{
	// Optional: Show a waiting message in the layer with ID login_response

	showLoadingPage();
	var tenGame= encodeURI(document.getElementById('txtTenGame').value);

	var linkGame = encodeURI(document.getElementById('txtLinkGame').value);

	var Price= encodeURI(document.getElementById('txtPrice').value);
	var Type = encodeURI(document.getElementById('cbxType').value);
	var device = encodeURI(document.getElementById('cbxDevice').value);
	var hot = encodeURI(document.getElementById('chkHot').checked?1:0);
	
	 arguments0 = {
    ten: tenGame,
	mlink: linkGame,
	ty: Type,
	de: device,
	pri: Price,
	ho: hot
  };
  $.ajax({
     type: "POST",
     url: "process/insert.php",
     data: {arguments1: arguments0},
     success: function(data) {
       $("#review").html(data);   
	 	$("#loadingpage").fadeOut(1000);
		
    }
  });
}
function loadCart(page)
{
	
	url = "process/processCart.php?page="+page;
		http.open("get",url,true);
		http.onreadystatechange=processCart;
		http.send(null);
}
function processCart(){
	if(http.readyState == 4){
		$('#cartContentsDisplay').html(http.responseText);	
	}
}
function loadGame(id,p){

	url = "process/processListGame.php?id="+id+"&page="+p;
	http.open("get",url,true);
	http.onreadystatechange=process;
	http.send(null);
}

function process(){
	if(http.readyState == 4 && http.status == 200){
		$('#ketqua').html(http.responseText);
		$("#loadingpage").fadeOut(1000);	
	}
}
function add(obj)
{	
	id = obj.getAttribute("id");
	var gameID = id.split("_")[1];
	if(obj.getAttribute('class')=='unSelect')
	{
		url = "process/processAdd.php?id="+gameID+"&temp=1";
	}
	else
	{
		url = "process/processAdd.php?id="+gameID+"&temp=0";
	}
	http.open("get",url,true);
	http.onreadystatechange=processAdd;
	http.send(null);
	selecte(''+gameID);
}

function processAdd(){
	if(http.readyState == 4 && http.status == 200){
		$("#test").html(http.responseText);	
	}
}
function loadScreenShoot(idScreenShoot){

	
	url = "process/processScreenShoot.php?idScreenShoot="+idScreenShoot;
	http.open("get",url,true);
	http.onreadystatechange=processScreenShoot;
	http.send(null);	

}

function processScreenShoot(){
	if(http.readyState == 4 && http.status == 200){

		$('body').append(http.responseText);	
		$("#21").click();
		
	}
}
function removeCart(gameID)
{
	$("#undelete"+gameID).show();
	$("#delete"+gameID).hide();
	url = "process/processAdd.php?id="+gameID+"&temp=0";
	http.open("get",url,true);
	http.onreadystatechange=processAddRe;
	http.send(null);
	}
function addCart(gameID)
{
	$("#delete"+gameID).show();
	$("#undelete"+gameID).hide();
	url = "process/processAdd.php?id="+gameID+"&temp=1";
	http.open("get",url,true);
	http.onreadystatechange=processAddRe;
	http.send(null);
	}
function processAddRe(){
if(http.readyState == 4 && http.status == 200){
	$("#test").html(http.responseText);	
}
}
